home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: ls find.c
-
- Purpose: This module handles the "find problem" option.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "ls find.h"
- #include "ls meat.h"
- #include "dialogs.h"
- #include "menus.h"
- #include "program globals.h"
-
- static Boolean gIsShowingFind;
- static short gProblemRow1, gProblemRow2, gProblemColumn1, gProblemColumn2;
-
- void InitFind(void)
- {
- gIsShowingFind=FALSE;
- }
-
- void FindDispatch(ExtendedWindowDataHandle theData)
- {
- if (FindProblem(&gProblemRow1, &gProblemColumn1, &gProblemRow2, &gProblemColumn2))
- {
- gIsShowingFind=TRUE;
- AdjustMenus();
- DrawMenuBar();
- UpdateTheWindow(theData);
- }
- else
- {
- PositionDialog('ALRT', smallAlert);
- ParamText("\pThere are no problems on the current playing board.","\p","\p","\p");
- NoteAlert(smallAlert, 0L);
- }
- }
-
- Boolean ShowingFindQQ(void)
- {
- return gIsShowingFind;
- }
-
- void DontShowFind(WindowDataHandle theData)
- {
- gIsShowingFind=FALSE;
- AdjustMenus();
- DrawMenuBar();
- UpdateTheWindow((ExtendedWindowDataHandle)theData);
- }
-
- void GetProblemPositions(short *row1, short *column1, short *row2, short *column2)
- {
- *row1=gProblemRow1;
- *column1=gProblemColumn1;
- *row2=gProblemRow2;
- *column2=gProblemColumn2;
- }
-
- Boolean FindProblem(short *problemRow, short *problemColumn, short *problemRow2,
- short *problemColumn2)
- {
- short theRow, theColumn;
- short rowIter, columnIter;
- short startRow, startColumn;
-
- /* check for identical pieces in the same row */
- for (theRow=0; theRow<gNumRows; theRow++)
- {
- for (theColumn=0; theColumn<gNumColumns-1; theColumn++)
- {
- if (Board[theRow][theColumn]>0)
- {
- for (columnIter=theColumn+1; columnIter<gNumColumns; columnIter++)
- {
- if (Board[theRow][theColumn]==Board[theRow][columnIter])
- {
- *problemRow=*problemRow2=theRow;
- *problemColumn=theColumn;
- *problemColumn2=columnIter;
- return TRUE;
- }
- }
- }
- }
- }
-
- /* check for identical pieces in the same column */
- for (theColumn=0; theColumn<gNumColumns; theColumn++)
- {
- for (theRow=0; theRow<gNumRows-1; theRow++)
- {
- if (Board[theRow][theColumn]>0)
- {
- for (rowIter=theRow+1; rowIter<gNumRows; rowIter++)
- {
- if (Board[theRow][theColumn]==Board[rowIter][theColumn])
- {
- *problemRow=theRow;
- *problemRow2=rowIter;
- *problemColumn=*problemColumn2=theColumn;
- return TRUE;
- }
- }
- }
- }
- }
-
- theRow=gNumRows-2;
- theColumn=0;
-
- while (theColumn<gNumColumns-1)
- {
- startRow=theRow;
- startColumn=theColumn;
-
- while ((startRow<gNumRows-1) && (startColumn<gNumColumns-1))
- {
- if (Board[startRow][startColumn]>0)
- {
- rowIter=startRow+1;
- columnIter=startColumn+1;
-
- while ((rowIter<gNumRows) && (columnIter<gNumColumns))
- {
- if (Board[startRow][startColumn]==Board[rowIter][columnIter])
- {
- *problemRow=startRow;
- *problemColumn=startColumn;
- *problemRow2=rowIter;
- *problemColumn2=columnIter;
- return TRUE;
- }
-
- rowIter++;
- columnIter++;
- }
- }
-
- startRow++;
- startColumn++;
- }
-
- if (theRow==0)
- theColumn++;
- else
- theRow--;
- }
-
- theRow=1;
- theColumn=0;
-
- while (theColumn<gNumColumns-1)
- {
- startRow=theRow;
- startColumn=theColumn;
-
- while ((startRow>=0) && (startColumn<gNumColumns))
- {
- if (Board[startRow][startColumn]>0)
- {
- rowIter=startRow-1;
- columnIter=startColumn+1;
-
- while ((rowIter>=0) && (columnIter<gNumColumns))
- {
- if (Board[startRow][startColumn]==Board[rowIter][columnIter])
- {
- *problemRow=startRow;
- *problemColumn=startColumn;
- *problemRow2=rowIter;
- *problemColumn2=columnIter;
- return TRUE;
- }
-
- rowIter--;
- columnIter++;
- }
- }
-
- startRow--;
- startColumn++;
- }
-
- if (theRow==gNumRows-1)
- theColumn++;
- else
- theRow++;
- }
-
- return FALSE; /* no problems found */
- }
-